﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 图解算法数据结构._06_ReversePrint
{

    public class ListNode
    {
        public int val;
        public ListNode next;
        public ListNode(int x) { val = x; }
    }
    class MainProject
    {
        static void Main(string[] args)
        {
            ListNode listNode1 = new ListNode(1);
            listNode1.next = new ListNode(3);
            listNode1.next.next = new ListNode(2);
            foreach (var item in ReversePrint(listNode1))
            {
                Console.WriteLine(item);
            }
            Console.ReadKey();
        }
        public static int[] ReversePrint(ListNode head)
        {
            if (head==null) return new int[] { };
            Stack<int> s = new Stack<int>();
            while (true)
            {
                s.Push(head.val);
                if (head.next == null) break;
                else head = head.next;
            }
            int[] array = s.ToArray();
            return array;
        }
    }
}
